<template>
   <div>
        <div class="head">
            首页 &nbsp;/ &nbsp;用户管理 &nbsp;/
            <span>修改</span>
        </div>
        <el-form
            :model="ruleForm"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
            :data="newArr"
        >
            <el-form-item label="套餐名字" prop="account">
                <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="价格" prop="normalPrice">
                <el-input v-model="ruleForm.normalPrice"></el-input>
            </el-form-item>
            <el-form-item label="打折价格" prop="salePrice">
                <el-input v-model="ruleForm.salePrice"></el-input>
            </el-form-item>
            <el-form-item label="月份" prop="mouth">
                <el-input v-model="ruleForm.mouth"></el-input>
            </el-form-item>
            <el-form-item label="是否推荐" prop="type">
                <el-input v-model="ruleForm.type"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const {  mapState, mapActions } = createNamespacedHelpers("recipeModules");
export default {
         data(){
        return {
            ruleForm: {
                _id:'',
                name: '',
                normalPrice: '',
                salePrice: '',
                mouth: '',
                type:''
              

            },
            
        }
  },

  methods:{
         ...mapActions(['asyncUpDataRecipe']),
         submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.asyncUpDataRecipe({
                        _id:this.ruleForm._id,
                        name:this.ruleForm.name,
                        normalPrice:this.ruleForm.normalPrice,
                        salePrice:this.ruleForm.salePrice,
                        mouth:this.ruleForm.mouth,
                        type:this.ruleForm.type,
                    })
                    alert('修改成功');

                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        }
  },
    computed:{
      ...mapState(['newArr'])
  },
  created(){
      console.log(this.newArr);
      this.ruleForm=this.newArr
  }
  
}
</script>

<style lang="scss" scoped>
 .head {
    width: 1250px;
    height: 80px;
    border-bottom: 1px solid #ccc;
    text-align: left;
    line-height: 70px;
    font-size: 20px;
    color: #a4a4a4;
    span {
        color: black;
        font-weight: 600;
    }
}
</style>